/*
	Copyright (c) 2010 <copyright holders>
	This source code is licensed under The MIT License,
	see the file LICENSE for details.
	*/

#ifndef WORLDSCENE_HPP
#define WORLDSCENE_HPP

#include <boost/unordered_map.hpp>

#include "ForwardDecls.hpp"
#include "SquadSelection.hpp"
#include "World.hpp" //mut this be included here???

namespace spelprog2 {
namespace presentation {

class WorldScene {
    typedef boost::shared_ptr<UnitInterpolator> UnitInterpolatorPtr;
    typedef boost::shared_ptr<EntityInterpolator> EntityInterpolatorPtr;
    typedef boost::unordered_map<sim::Unit::ConstPointer, UnitInterpolatorPtr> UnitEntityMap;
    typedef boost::unordered_map<sim::WideInt, EntityInterpolatorPtr> ProjectileEntityMap; //TODO: make special class for projectiles
    typedef std::map<std::string, SquadSelections> SquadSelectionsMap;

    sim::WorldManager & worldMan_;
    Ogre::SceneManager & sceneMan_;
    UnitEntityMap unitEnts_;
    ProjectileEntityMap projectileEnts_; 

    SquadSelections activeSquadSelections_;
    SquadSelectionsMap groupedSquadSelections_;

    void markSelectedUnits();
public:
    WorldScene(sim::WorldManager & worldMan, Ogre::SceneManager & sceneMan);
    ~WorldScene();

    void gfxUpdate(float deltaTime);

    void onWorldUpdated(const sim::World & world);
    void onUnitAdded(sim::Unit::ConstPointer unit, sim::Int playerId, sim::Int squadId);
    void onUnitRemoved(sim::Unit::ConstPointer unit);
    void onProjectileAdded(const sim::Projectile & projectile);
    void onProjectileRemoved(const sim::Projectile & projectile);

    void clearSelectedSquads();
    bool friendlySquadsSelected() const;
    void addToSelectedSquads(const SquadSelection & sel);
    void removeFromSelectedSquads(const SquadSelection & sel);
    SquadSelections::ConstIteratorRange getSelectedSquads() const;
    void storeSelectedSquadsGroup(const std::string & key);
    void addGroupToSelectedSquads(const std::string & key);
};

};
};

#endif  //WORLDSCENE_HPP